Formalizing Resourve Allocation in a Compiler
نویسنده
چکیده
On the basis of an A-normal form intermediate language we formally specify resource allocation in a compiler for a strict functional language. Here, resource is to be understood in the most general sense: registers, temporaries, data representations, etc. All these should be (and can be, but have never been) speciied formally. Our approach employs a non-standard annotated type system for the formalization. Although A-normal form turns out not to be the ideal vehicle for this investigation, we can prove some basic properties using the formalization. Resource allocation in the back end of a compiler is often poorly speciied. More often than not register allocation, administration of temporaries, and representation conversions are only speciied procedurally 1, 6]. Code generators based on such algorithmic speciications can be hard to maintain or prove correct. Even the authors of such code generators are sometimes not aware of all the invariants that must be preserved. Therefore, we investigate a declarative approach to resource allocation in the back end of a compiler. The approach is based on an annotated type system of implementation types that makes resource allocation and conversion explicit. The use of type conversion rules enables us to defer memory and register allocation until the context of use forces an allocation. For example, a constant initially leads to an annotation of the type of the variable holding the constant without generating any code. The annotation holds the \immediate value" of the constant. There are type conversion rules that change the annotation from \immediate value" to \value in register k" and generate a corresponding piece of code if the context of use requires the value of the variable in a register. Further conversion rules create or remove indirection. The indirection rules move a value to memory and change the annotation to \value in memory at address Rk]+i", where Rk] is an address in register k and i is an ooset. The indirection removing rules work the other way round. The indirection rules usually apply to the arguments of function calls or to values that are put into data structures. Spilling the contents of registers is another application of the last kind of conversion rules. Other rules may make direct use of immediate values, for example when generating instructions with immediate operands.
منابع مشابه
A Precise Memory Model for Low-Level Bounded Model Checking
Formalizing the semantics of programming languages like C or C++ for bounded model checking can be cumbersome if complete coverage of all language features is to be achieved. On the other hand, low-level languages that occur during translation (compilation) have a much simpler semantics since they are closer to the machine level. It thus makes sense to use these low-level languages for bounded ...
متن کاملA survey of register allocation
One of the most important functions a compiler must perform is the allocation of reg isters for the instruction stream it generates. In addition to assuring that the allocation of registers is consistent with the semantics of the program being compiled, many compilers attempt to maKe 'optimal' use of the registers. A survey of work in the area of optimal register allocation is presented, and th...
متن کاملFormalizing and Verifying Semantic Type Soundness of a Simple Compiler (Preliminary Report)
We describe a semantic type soundness result, formalized in the Coq proof assistant, for a compiler from a simple imperative language with heap-allocated data into an idealized assembly language. Types in the high-level language are interpreted as binary relations, built using both second-order quantification and a form of separation structure, over stores and code pointers in the low-level mac...
متن کاملCU - CS - 82 - 130 Topics in Code Generation and Register Allocation
This paper discusses some questions about register allocation and code generation in optimizing compilers. The context of the research is the PQCC (Production Quality Compiler-Compiler) project. The questions discussed include fundamental questions of compiler structure. that is, questions of the feasibility and correctness of the approach taken by the project. I also report on less fundamental...
متن کاملTopics in code generation and register allocation
This paper discusses some questions about register allocation and code generation in optimizing compilers. The context of the research is the PQCC (Production Quality Compiler-Compiler) project. The questions discussed include fundamental questions of compiler structure, that is, questions of the feasibility and correctness of the approach taken by the project. I also report on less fundamental...
متن کامل